let state = {
	userInfo: uni.getStorageSync("userInfo") || {},
	staffInfo: uni.getStorageSync("staffInfo") || {},
	ggUuid: uni.getStorageSync("ggUuid") || "",
	staffId: uni.getStorageSync("staffId") || "",
	shareId: uni.getStorageSync("shareId") || "",
	spGiUuid: uni.getStorageSync("spGiUuid") || "",
};

let getters = {
	userInfo: (state) => state.userInfo,
	staffInfo: (state) => state.staffInfo,
	ggUuid: (state) => state.ggUuid,
	staffId: (state) => state.staffId,
	shareId: (state) => state.shareId,
	spGiUuid: (state) => state.spGiUuid,
};

let mutations = {
	updateState(state, payload) {
		for (const key in payload) {
			if (Object.hasOwnProperty.call(payload, key)) {
				state[key] = payload[key];
				uni.setStorageSync(key, payload[key]);
			}
		}
	},
};

let actions = {
	save(context, payload) {
		context.commit("updateState", payload);
	},
	saveParams(context, payload) {
		const {
			staffId,
			shareId
		} = payload;
		if (staffId && !state.staffInfo?.orUuid) {
			context.commit("updateState", {
				staffId
			});
		}
		if (shareId) context.commit("updateState", {
			shareId
		});
	},
};

export default {
	namespaced: true,
	state,
	getters,
	mutations,
	actions,
};
